package com.szq.netty.client;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.EventLoop;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName: MyChannelFutureListener
 * @Description:
 * @Author: szq
 * @Date: 2021-11-17 11:09:10
 */
public class MyChannelFutureListener implements ChannelFutureListener {

    @Override
    public void operationComplete(ChannelFuture channelFuture) {
        if (channelFuture.isSuccess()) {
            System.out.println("netty-demo-208 client start done......");
            return;
        }
        final EventLoop loop = channelFuture.channel().eventLoop();
        loop.schedule(() -> {
            try {
                new NettyClient().connect("192.168.30.32", 7397);
                System.out.println("netty-demo-208 client start done.....");
                Thread.sleep(500);
            } catch (Exception e){
                System.out.println("netty-demo-208 client start error go reconnect......");
            }
        }, 1L, TimeUnit.SECONDS);
    }
}
